home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / doom / suckmods.zip / SUCKMODS.ZIP / suck05 / src / status.qc < prev    next >
Text File  |  1997-05-11  |  15KB  |  537 lines

  1. //         The CTF status bar, by Suck (Nat Friedman)
  2. // This file may not be redistributed without the accompanying GNU Public License.
  3.  
  4. // Let me just clear up one thing about the way this works:  Basically, a centerprint
  5. // packet consists of a byte identifying it as a centerprint (26 decimal), followed
  6. // by a zero-terminated string.  In order to construct this in a piece-wise manner,
  7. // which is what the status bar does, we _cannot_ use WriteString because some silly
  8. // ass decided that this should null-terminate the string, reducing the flexibility
  9. // of the function by orders of magnitude.  So, I wanted to write 4 bytes of the
  10. // string at a time using WriteLong(), but for whatever reason, the high byte is always
  11. // corrupted, so I write 2 bytes at a time using WriteShort(), and rendering my code
  12. // somewhat hard to read or understand at first pass.
  13.  
  14. // Prototypes.  Function descriptions can be found with their respective functions.
  15. void() bottomline;
  16. void(float f) printnum;
  17. void() bottomline;
  18. void(float r) printrune;
  19.  
  20. // Globals
  21. float team1total;
  22. float team2total;
  23. float totallastcomputed;
  24.  
  25. // Print the status bar or any special messages for client "self"
  26. void() printstatus =
  27. {
  28.     local float winner, spread;
  29.     local entity p;
  30.  
  31.     // Set the entity for the unicast Write*()s
  32.     msg_entity=self;
  33.  
  34.     // 26 == SVC_CENTERPRINT
  35.     WriteByte(MSG_ONE, 26);
  36.  
  37.     // Give us enough newlines to get to the bottom line.  msg_center
  38.     // is used for a special message which needs to be printed in the
  39.     // center of the screen, like a rune notification.
  40.     if (!self.msg_center)
  41.         bottomline();
  42.     self.msg_center=0;
  43.  
  44.     // Print any pending message 
  45.     if (self.msg_pending)
  46.     {
  47.         WriteString(MSG_ONE, self.msg_string);
  48.         self.msg_pending=0;
  49.         return;
  50.     }
  51.  
  52.     // Calculate the team scores.
  53.     if (totallastcomputed < (time - 2))
  54.     {
  55.         totallastcomputed=time;
  56.             team1total = team2total = 0;
  57.             p = find(world, classname, "player");
  58.             while (p != world) {
  59.                     if (p.lastteam == TEAM_COLOR1 + 1)
  60.             {
  61.                 if (teamplay&TEAM_CAPTURE_UNIF)
  62.                 {
  63.                     if (p.frags > team1total)
  64.                         team1total=p.frags;
  65.                     }
  66.                 else
  67.                     team1total = team1total + p.frags;
  68.             }
  69.                     else if (p.lastteam == TEAM_COLOR2 + 1)
  70.                 if (teamplay&TEAM_CAPTURE_UNIF)
  71.                 {
  72.                     if (p.frags>team2total)
  73.                         team2total=p.frags;
  74.                 }
  75.                 else
  76.                                 team2total = team2total + p.frags;
  77.                     p = find(p, classname, "player");
  78.         }
  79.     }
  80.  
  81.     // Print the player's rune name as the first entry in the status
  82.     // bar.
  83.     printrune(self.rune_num);
  84.  
  85.     // Space
  86.     WriteByte(MSG_ONE, 32);
  87.  
  88.     // "Kills:"
  89.         WriteShort(MSG_ONE, -5685);
  90.         WriteShort(MSG_ONE, -4884);
  91.         WriteShort(MSG_ONE, 15091);
  92.  
  93.     printnum(self.num_kills);
  94.  
  95.     // Space
  96.     WriteByte(MSG_ONE, 32);
  97.  
  98.     // "Deaths:"
  99.         WriteShort(MSG_ONE, -6716);
  100.         WriteShort(MSG_ONE, -2847);
  101.         WriteShort(MSG_ONE, -3096);
  102.         WriteByte(MSG_ONE, 58);
  103.  
  104.     printnum(self.num_deaths);
  105.  
  106.     // Space
  107.     WriteByte(MSG_ONE, 32);
  108.  
  109.     if (team1total == team2total)
  110.     {
  111.         // "Tie "
  112.             WriteShort(MSG_ONE, -5676);
  113.             WriteShort(MSG_ONE, 8421);
  114.     }
  115.     else if (team1total > team2total)
  116.     {
  117.         // "Red "
  118.             WriteShort(MSG_ONE, -6702);
  119.             WriteShort(MSG_ONE, 8420);
  120.     }
  121.     else
  122.     {
  123.         // "Blue"
  124.             WriteShort(MSG_ONE, -4926);
  125.             WriteShort(MSG_ONE, -6667);
  126.     }
  127.  
  128.     spread=fabs(team1total-team2total);
  129.     printnum(spread);
  130.  
  131.     // Newline, EOL
  132.     WriteByte(MSG_ONE, 10);
  133.     WriteByte(MSG_ONE, 0);
  134. };
  135.  
  136. // This is the function you should use in place of centerprint if
  137. // you need to send a message to the client.  Note that the message
  138. // will appear on the bottom line unless you do something like this:
  139. //  self.msg_center=1;
  140. //   clientmsg(self, "Something important has happened!\n");
  141. void(entity p, string st) clientmsg =
  142. {
  143.     if (st == "")
  144.     {
  145.         p.msg_center=0;
  146.         return;
  147.     }
  148.     p.msg_pending=1;
  149.     p.msg_string=st;
  150. };
  151.  
  152. // Print the name of the rune.  This is always 11 characters long.
  153. void(float r) printrune =
  154. {
  155.     if (r==ITEM_RUNE_RESIST) {
  156.     // Earth Magic
  157.         WriteShort(MSG_ONE, 24901);
  158.         WriteShort(MSG_ONE, 29810);
  159.         WriteShort(MSG_ONE, 8296);
  160.         WriteShort(MSG_ONE, 24909);
  161.         WriteShort(MSG_ONE, 26983);
  162.         WriteByte(MSG_ONE, 99);
  163.     return;
  164.     }
  165.     else if (r==ITEM_RUNE_DBLDMG) {
  166.     // Black Magic
  167.         WriteShort(MSG_ONE, 27714);
  168.         WriteShort(MSG_ONE, 25441);
  169.         WriteShort(MSG_ONE, 8299);
  170.         WriteShort(MSG_ONE, 24909);
  171.         WriteShort(MSG_ONE, 26983);
  172.         WriteByte(MSG_ONE, 99);
  173.     return;
  174.     }
  175.     else if (r==ITEM_RUNE_HASTE) {
  176.     // Hell Magic 
  177.         WriteShort(MSG_ONE, 25928);
  178.         WriteShort(MSG_ONE, 27756);
  179.         WriteShort(MSG_ONE, 19744);
  180.         WriteShort(MSG_ONE, 26465);
  181.         WriteShort(MSG_ONE, 25449);
  182.         WriteByte(MSG_ONE, 32);
  183.     return;
  184.     }
  185.     else if (r==ITEM_RUNE_REGEN) {
  186.     // Elder Magic
  187.         WriteShort(MSG_ONE, 27717);
  188.         WriteShort(MSG_ONE, 25956);
  189.         WriteShort(MSG_ONE, 8306);
  190.         WriteShort(MSG_ONE, 24909);
  191.         WriteShort(MSG_ONE, 26983);
  192.         WriteByte(MSG_ONE, 99);
  193.     return;
  194.     }
  195.     else if (r==ITEM_RUNE_PRIEST) {
  196.     // Priest Rune
  197.         WriteShort(MSG_ONE, 29264);
  198.         WriteShort(MSG_ONE, 25961);
  199.         WriteShort(MSG_ONE, 29811);
  200.         WriteShort(MSG_ONE, 21024);
  201.         WriteShort(MSG_ONE, 28277);
  202.         WriteByte(MSG_ONE, 101);
  203.     return;
  204.     }
  205.     else if (r==ITEM_RUNE_VAMPIRE) {
  206.     // Vampire
  207.         WriteShort(MSG_ONE, 24918);
  208.         WriteShort(MSG_ONE, 28781);
  209.         WriteShort(MSG_ONE, 29289);
  210.         WriteShort(MSG_ONE, 8293);
  211.         WriteShort(MSG_ONE, 8224);
  212.         WriteByte(MSG_ONE, 32);
  213.     return;
  214.     }
  215.     else if (r==ITEM_RUNE_CASTLE) {
  216.     // Castle Rune
  217.         WriteShort(MSG_ONE, 24899);
  218.         WriteShort(MSG_ONE, 29811);
  219.         WriteShort(MSG_ONE, 25964);
  220.         WriteShort(MSG_ONE, 21024);
  221.         WriteShort(MSG_ONE, 28277);
  222.         WriteByte(MSG_ONE, 101);
  223.     return;
  224.     }
  225.     else if (r==ITEM_RUNE_SIEGE) {
  226.     // Siege Rune
  227.         WriteShort(MSG_ONE, 26963);
  228.         WriteShort(MSG_ONE, 26469);
  229.         WriteShort(MSG_ONE, 8293);
  230.         WriteShort(MSG_ONE, 30034);
  231.         WriteShort(MSG_ONE, 25966);
  232.     WriteByte(MSG_ONE, 32);
  233.     return;
  234.     }
  235.     else if (r==ITEM_RUNE_HERMES) {
  236.     // Hermes
  237.         WriteShort(MSG_ONE, 25928);
  238.         WriteShort(MSG_ONE, 28018);
  239.         WriteShort(MSG_ONE, 29541);
  240.         WriteShort(MSG_ONE, 8224);
  241.         WriteShort(MSG_ONE, 8224);
  242.         WriteByte(MSG_ONE, 32);
  243.     }
  244.     else if (r==ITEM_RUNE_VULCAN) {
  245.     // Vulcan
  246.         WriteShort(MSG_ONE, 30038);
  247.         WriteShort(MSG_ONE, 25452);
  248.         WriteShort(MSG_ONE, 28257);
  249.         WriteShort(MSG_ONE, 8224);
  250.         WriteShort(MSG_ONE, 8224);
  251.         WriteByte(MSG_ONE, 32);
  252.     }
  253.     else if (r==ITEM_RUNE_MARS) {
  254.     // Mars
  255.         WriteShort(MSG_ONE, 24909);
  256.         WriteShort(MSG_ONE, 29554);
  257.         WriteShort(MSG_ONE, 8224);
  258.         WriteShort(MSG_ONE, 8224);
  259.         WriteShort(MSG_ONE, 8224);
  260.         WriteByte(MSG_ONE, 32);
  261.     }
  262.     else if (r==ITEM_RUNE_POSEIDON) {
  263.     // Poseidon
  264.         WriteShort(MSG_ONE, 28496);
  265.         WriteShort(MSG_ONE, 25971);
  266.         WriteShort(MSG_ONE, 25705);
  267.         WriteShort(MSG_ONE, 28271);
  268.         WriteShort(MSG_ONE, 8224);
  269.         WriteByte(MSG_ONE, 32);
  270.     }
  271.     else if (r==ITEM_RUNE_LOKI) {
  272.         WriteShort(MSG_ONE, 28492);
  273.         WriteShort(MSG_ONE, 26987);
  274.         WriteShort(MSG_ONE, 8224);
  275.         WriteShort(MSG_ONE, 8224);
  276.         WriteShort(MSG_ONE, 8224);
  277.         WriteByte(MSG_ONE, 32);
  278.     }
  279.     else if (r==ITEM_RUNE_WENDIGO) {
  280.         WriteShort(MSG_ONE, 25943);
  281.         WriteShort(MSG_ONE, 25710);
  282.         WriteShort(MSG_ONE, 26473);
  283.         WriteShort(MSG_ONE, 8303);
  284.         WriteShort(MSG_ONE, 8224);
  285.         WriteByte(MSG_ONE, 32);
  286.     }
  287.     else if (r==ITEM_RUNE_THOR) {
  288.         WriteShort(MSG_ONE, 26708);
  289.         WriteShort(MSG_ONE, 29295);
  290.         WriteShort(MSG_ONE, 20512);
  291.         WriteShort(MSG_ONE, 30575);
  292.         WriteShort(MSG_ONE, 29285);
  293.         WriteByte(MSG_ONE, 32);
  294.     }
  295.     else if (r==ITEM_RUNE_WOLVERINE) {
  296.         WriteShort(MSG_ONE, 28503);
  297.         WriteShort(MSG_ONE, 30316);
  298.         WriteShort(MSG_ONE, 29285);
  299.         WriteShort(MSG_ONE, 28265);
  300.         WriteShort(MSG_ONE, 8293);
  301.         WriteByte(MSG_ONE, 32);
  302.     }
  303.     else if (r==ITEM_RUNE_WEREWOLF) {
  304.         WriteShort(MSG_ONE, 25943);
  305.         WriteShort(MSG_ONE, 25970);
  306.         WriteShort(MSG_ONE, 28535);
  307.         WriteShort(MSG_ONE, 26220);
  308.         WriteShort(MSG_ONE, 8224);
  309.         WriteByte(MSG_ONE, 32);
  310.     }
  311.     else if (r==ITEM_RUNE_WITCH) {
  312.         WriteShort(MSG_ONE, 26967);
  313.         WriteShort(MSG_ONE, 25460);
  314.         WriteShort(MSG_ONE, 8296);
  315.         WriteShort(MSG_ONE, 8224);
  316.         WriteShort(MSG_ONE, 8224);
  317.         WriteByte(MSG_ONE, 32);
  318.     }
  319.     else if (r==ITEM_RUNE_VIKING) {
  320.         WriteShort(MSG_ONE, 26966);
  321.         WriteShort(MSG_ONE, 26987);
  322.         WriteShort(MSG_ONE, 26478);
  323.         WriteShort(MSG_ONE, 8224);
  324.         WriteShort(MSG_ONE, 8224);
  325.         WriteByte(MSG_ONE, 32);
  326.     }
  327.     else if (r==ITEM_RUNE_STORMCROW) {
  328.         WriteShort(MSG_ONE, 29779);
  329.         WriteShort(MSG_ONE, 29295);
  330.         WriteShort(MSG_ONE, 17261);
  331.         WriteShort(MSG_ONE, 28530);
  332.         WriteShort(MSG_ONE, 8311);
  333.         WriteByte(MSG_ONE, 32);
  334.     }
  335.     else if (r==ITEM_RUNE_POCAHONTAS) {
  336.     WriteShort(MSG_ONE, 28496);
  337.         WriteShort(MSG_ONE, 24931);
  338.         WriteShort(MSG_ONE, 28520);
  339.         WriteShort(MSG_ONE, 29806);
  340.         WriteShort(MSG_ONE, 29537);
  341.         WriteByte(MSG_ONE, 32);
  342.     }
  343.     else if (r==ITEM_RUNE_ARTHUR)
  344.     {
  345.         WriteShort(MSG_ONE, 26955);
  346.         WriteShort(MSG_ONE, 26478);
  347.         WriteShort(MSG_ONE, 16672);
  348.         WriteShort(MSG_ONE, 29810);
  349.         WriteShort(MSG_ONE, 30056);
  350.         WriteByte(MSG_ONE, 114);
  351.     }
  352.     else if (r == ITEM_RUNE_GOLOM)
  353.     {
  354.         WriteShort(MSG_ONE, 28487);
  355.         WriteShort(MSG_ONE, 28524);
  356.         WriteShort(MSG_ONE, 8301);
  357.         WriteShort(MSG_ONE, 8224);
  358.         WriteShort(MSG_ONE, 8224);
  359.         WriteByte(MSG_ONE, 32);
  360.     }
  361.     else if (r==ITEM_RUNE_SAMURAI)
  362.     {
  363.         WriteShort(MSG_ONE, 24915);
  364.         WriteShort(MSG_ONE, 30061);
  365.         WriteShort(MSG_ONE, 24946);
  366.         WriteShort(MSG_ONE, 8297);
  367.         WriteShort(MSG_ONE, 8224);
  368.         WriteByte(MSG_ONE, 32);
  369.     }
  370.     else if (r==ITEM_RUNE_SHYLOCK)
  371.     {
  372.             WriteShort(MSG_ONE, 26707);
  373.         WriteShort(MSG_ONE, 27769);
  374.         WriteShort(MSG_ONE, 25455);
  375.         WriteShort(MSG_ONE, 8299);
  376.         WriteShort(MSG_ONE, 8224);
  377.         WriteByte(MSG_ONE, 32);
  378.  
  379.     }
  380.     else if (r==ITEM_RUNE_IFRITE)
  381.     {
  382.         WriteShort(MSG_ONE, 26185);
  383.         WriteShort(MSG_ONE, 26994);
  384.         WriteShort(MSG_ONE, 25972);
  385.         WriteShort(MSG_ONE, 8224);
  386.         WriteShort(MSG_ONE, 8224);
  387.         WriteByte(MSG_ONE, 32);
  388.     }
  389.     else if (r==ITEM_RUNE_SARGON)
  390.     {
  391.         WriteShort(MSG_ONE, 24915);
  392.         WriteShort(MSG_ONE, 26482);
  393.         WriteShort(MSG_ONE, 28271);
  394.         WriteShort(MSG_ONE, 8224);
  395.         WriteShort(MSG_ONE, 8224);
  396.         WriteByte(MSG_ONE, 32);
  397.     }
  398.     else if (r==ITEM_RUNE_KIZI)
  399.     {
  400.         WriteShort(MSG_ONE, 26955);
  401.         WriteShort(MSG_ONE, 27002);
  402.         WriteShort(MSG_ONE, 8224);
  403.         WriteShort(MSG_ONE, 8224);
  404.         WriteShort(MSG_ONE, 8224);
  405.         WriteByte(MSG_ONE, 32);
  406.     }
  407.     else if (r==ITEM_RUNE_MONK)
  408.     {
  409.         WriteShort(MSG_ONE, 28493);
  410.         WriteShort(MSG_ONE, 27502);
  411.         WriteShort(MSG_ONE, 8224);
  412.         WriteShort(MSG_ONE, 8224);
  413.         WriteShort(MSG_ONE, 8224);
  414.         WriteByte(MSG_ONE, 32);
  415.     }
  416.     else if (r==ITEM_RUNE_ANKH)
  417.     {
  418.         WriteShort(MSG_ONE, 28225);
  419.         WriteShort(MSG_ONE, 26731);
  420.         WriteShort(MSG_ONE, 8224);
  421.         WriteShort(MSG_ONE, 8224);
  422.         WriteShort(MSG_ONE, 8224);
  423.         WriteByte(MSG_ONE, 32);
  424.     }
  425.     else if (r==ITEM_RUNE_NINJA)
  426.     {
  427.         WriteShort(MSG_ONE, 26958);
  428.         WriteShort(MSG_ONE, 27246);
  429.         WriteShort(MSG_ONE, 8289);
  430.         WriteShort(MSG_ONE, 8224);
  431.         WriteShort(MSG_ONE, 8224);
  432.         WriteByte(MSG_ONE, 32);
  433.     }
  434.     else if (r==ITEM_RUNE_SAMURAI)
  435.     {
  436.         WriteShort(MSG_ONE, 24915);
  437.         WriteShort(MSG_ONE, 30061);
  438.         WriteShort(MSG_ONE, 24946);
  439.         WriteShort(MSG_ONE, 8297);
  440.         WriteShort(MSG_ONE, 8224);
  441.         WriteByte(MSG_ONE, 32);
  442.     }
  443.     else if (r==ITEM_RUNE_SHOGUN)
  444.     {
  445.         WriteShort(MSG_ONE, 26707);
  446.         WriteShort(MSG_ONE, 26479);
  447.         WriteShort(MSG_ONE, 28277);
  448.         WriteShort(MSG_ONE, 8224);
  449.         WriteShort(MSG_ONE, 8224);
  450.         WriteByte(MSG_ONE, 32);
  451.     }
  452.     else if (r==ITEM_RUNE_BALDER)
  453.     {
  454.         WriteShort(MSG_ONE, 24898);
  455.         WriteShort(MSG_ONE, 25708);
  456.         WriteShort(MSG_ONE, 29285);
  457.         WriteShort(MSG_ONE, 8224);
  458.         WriteShort(MSG_ONE, 8224);
  459.         WriteByte(MSG_ONE, 32);
  460.     }
  461.     else if (r==ITEM_RUNE_ALIBABA)
  462.     {
  463.         WriteShort(MSG_ONE, 27713);
  464.         WriteShort(MSG_ONE, 8297);
  465.         WriteShort(MSG_ONE, 24898);
  466.         WriteShort(MSG_ONE, 24930);
  467.         WriteShort(MSG_ONE, 8224);
  468.         WriteByte(MSG_ONE, 32);
  469.     }
  470.     else if (r==ITEM_RUNE_SANDSTORM)
  471.     {
  472.         WriteShort(MSG_ONE, 24915);
  473.         WriteShort(MSG_ONE, 25710);
  474.         WriteShort(MSG_ONE, 29811);
  475.         WriteShort(MSG_ONE, 29295);
  476.         WriteShort(MSG_ONE, 8301);
  477.         WriteByte(MSG_ONE, 32);
  478.     }
  479.     else if (r==ITEM_RUNE_WIND)
  480.     {
  481.         WriteShort(MSG_ONE, 26967);
  482.         WriteShort(MSG_ONE, 25710);
  483.         WriteShort(MSG_ONE, 21024);
  484.         WriteShort(MSG_ONE, 28277);
  485.         WriteShort(MSG_ONE, 8293);
  486.         WriteByte(MSG_ONE, 32);
  487.     }
  488.     else {
  489.         WriteShort(MSG_ONE, 28494);
  490.         WriteShort(MSG_ONE, 21024);
  491.         WriteShort(MSG_ONE, 28277);
  492.         WriteShort(MSG_ONE, 8293);
  493.         WriteShort(MSG_ONE, 8224);
  494.         WriteByte(MSG_ONE, 32);
  495.     }
  496. };
  497.  
  498. // This prints a 3 digit number (any more than 3 digits and you'll just get
  499. // 999).  It always fills 3 columns, so, for example, printnum(43) will
  500. // output " 43".   
  501. void(float f) printnum =
  502. {
  503.     local float d1, d2, d3;
  504.     local float a,b,c;
  505.  
  506.     if (f>999) f=999;
  507.     a=floor(f/10); a=a * 10; d1=f - a;
  508.     a=floor(f/100); a=a*100; a=f-(a+d1); d2=a/10;
  509.     d3=(f-(d1+(10*d2)))/100;
  510.     if (d3 == 0)
  511.         WriteByte(MSG_ONE, 32);
  512.     else
  513.         WriteByte(MSG_ONE, 48+d3);
  514.     if (d3 == 0 && d2 == 0)
  515.         WriteByte(MSG_ONE, 32);
  516.     else
  517.         WriteByte(MSG_ONE, 48+d2);
  518.     WriteByte(MSG_ONE, 48+d1);
  519. };
  520.  
  521. // Print 11 newlines.  You have to print the space because quake won't
  522. // count the line unless it has non-zero length.  These 11 lines get the
  523. // "cursor" down to the bottom line on most screens.  For people with
  524. // higher resolutions, they can just turn off the status bar.
  525. void() bottomline =
  526. {
  527.     local float i;
  528.     i=0;
  529.     while (i<self.bottom_line)
  530.     {
  531.         WriteByte(MSG_ONE, 32);
  532.         WriteByte(MSG_ONE, 10);
  533.         i=i + 1;
  534.     }
  535. };
  536.  
  537.